USE SAS
GO

 IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'BasicSearch')
	BEGIN
		DROP  Procedure  dbo.BasicSearch
	END

GO

CREATE Procedure dbo.BasicSearch
	@type		VARCHAR(20)
,	@text		VARCHAR(max)
,	@userId		INT
AS
BEGIN

	SET @text = '%'+@text+'%'

	IF(@type = 'Accounts')
		exec SearchAccounts @text,@userId
	ELSE IF @type = 'Contacts'
		exec SearchContacts @text,@userId
	ELSE IF @type = 'Activities'
		exec SearchActivities @text,@userId
	ELSE IF @type = 'Tasks'
		exec SearchTasks @text,@userId
--	ELSE IF @type = 'Opportunities'
--		exec SearchOpportunities @text,@userId
	ELSE
	BEGIN
		SELECT '<DATA><RESPONSE>
					<RESULT>E</RESULT>
					<MESSAGE>Invalid Search Type</MESSAGE>
				</RESPONSE></DATA>'
		
	END
END
GO

-- exec BasicSearch 1